IF EXISTS (SELECT * FROM sysobjects WHERE type = 'P' AND name = 'spDepartments_RetrieveAll')
	BEGIN
		PRINT 'Dropping Procedure spDepartments_RetrieveAll'
		DROP  Procedure  spDepartments_RetrieveAll
	END

GO

PRINT 'Creating Procedure spDepartments_RetrieveAll'
GO

CREATE Procedure spDepartments_RetrieveAll
	(
		@DivisionName varchar(50) = null, 
		@DepartmentName varchar(50) = null, 
		@PrimaryAuthUser_ID numeric(9,0) = null, 
		@SecondaryAuthUser_ID numeric(9,0) = null
	)
AS
    /* 
    ------------------------------------------------------------------------------
    - Change History
    - --------------
    - Date          Description
    ------------------------------------------------------------------------------
    - 2007/11/02	Initial version created
    ------------------------------------------------------------------------------
    */
	
	SET NOCOUNT ON
	
	-- Retrieve the relevant records
	SELECT  *
	FROM	Departments
	
	WHERE	(@DivisionName IS NULL OR Departments.DivisionName LIKE @DivisionName + '%')
	  AND	(@DepartmentName IS NULL OR Departments.DepartmentName LIKE @DepartmentName + '%')
	  AND	(@PrimaryAuthUser_ID IS NULL OR Departments.PrimaryAuthUser_ID = @PrimaryAuthUser_ID)
	  AND	(@SecondaryAuthUser_ID IS NULL OR Departments.SecondaryAuthUser_ID = @SecondaryAuthUser_ID)

	-- Return to calling method
	RETURN
GO
